package wwek6;


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2 {
	private String name;
	private int age;
	public PersonSortable2(String name, int age) {
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		return name+"-"+age;
	}
	public String getName() {
		return name;
	}

	public int getAge() {
		return age;
	}


	
}
class AgeComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 o1, PersonSortable2 o2){
		if(o1.getAge()>o2.getAge())
			return o1.getAge()-o2.getAge();
		else if(o1.getAge()==o2.getAge())
			return 0;
		else return -1;
	}
}
class NameComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 o1, PersonSortable2 o2){
		return o1.getName().compareTo(o2.getName());
	}
	
}
public class PTA720402 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in =new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		PersonSortable2[] people=new PersonSortable2[n];
		for(int i=0;i<n;i++){
			PersonSortable2 person=new PersonSortable2(in.next(), in.nextInt());
			people[i]=person;
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(people, new NameComparator());
		for(int i=0;i<n;i++)
		System.out.println(people[i]);
		System.out.println("AgeComparator:sort");
		Arrays.sort(people, new AgeComparator());
		for(int i=0;i<n;i++)
		System.out.println(people[i]);
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}

}
